<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCursesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 课程
        Schema::create('curses', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->comment('课程名称');
            $table->integer('class_id')->comment('分类id')->default(0);
            $table->decimal('original_price',8,2)->default(0)->comment('原价');
            $table->decimal('sell_price',8,2)->default(0)->comment('卖价');
            $table->decimal('deposit_ratio',8,2)->default(0)->comment('定金比例');
            $table->integer('is_recommend')->default(2)->comment('推荐 1是 2否');
            $table->integer('visit')->default(0)->comment('观看人数');
            $table->longText('info')->nullable()->comment('详情');
            $table->string('cover_img')->default('')->comment('封面图');
            $table->integer('sort')->default(999)->nullable()->comment('排序');
            $table->timestamps();
        });
        // 轮播图
        Schema::create('curse_img', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('curse_id')->comment('课程id')->nullable();
            $table->string('img')->nullable()->comment('图片');
            $table->timestamps();
        });

        // 课程--评论
        Schema::create('curse_comment', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('curse_id')->comment('课程id');
            $table->integer('user_id')->comment('用户id');
            $table->text('content')->comment('内容')->nullable();
            $table->timestamps();
        });

        // 课程--章节
        Schema::create('curse_chapter', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('curse_id')->comment('课程id');
            $table->string('name')->nullable()->comment('章节名称');
            $table->longText('content')->nullable()->comment('介绍');
            $table->string('video')->nullable();
            $table->timestamps();
        });

        // 课程--分类
        Schema::create('curse_class', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->nullable()->comment('分类名称');
            $table->string('description')->default('')->comment('分类描述');
            $table->string('tag')->default('child')->comment('标识符');
            $table->integer('sort')->default(99)->comment('排序');
            $table->integer('pid')->default(0)->comment('父级');
            $table->timestamps();
        });

        // 观看记录
        Schema::create('curse_view', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('curse_id')->comment('课程id')->nullable();
            $table->integer('chapter_id')->comment('章节id')->nullable();
            $table->integer('user_id')->comment('用户id')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
